extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
mod orm;

#[proc_macro_derive(
    RustOrm,
    attributes(
        primary_key,// 标识主键，定义组键方法
        column,
    )
)]
pub fn orm_derive(input: TokenStream) -> TokenStream {
    let ast = parse_macro_input!(input as DeriveInput);
    let struct_name = &ast.ident;
    let table_info = orm::get_table_info(&ast);
    let impl_create = orm::impl_create(&table_info);
    let impl_insert = orm::impl_insert(&table_info);
    let impl_query = orm::impl_query(&table_info);
    let impl_delete = orm::impl_delete(&table_info);
    let impl_update = orm::impl_update(&table_info);

    quote! {
        impl #struct_name {
            #impl_create
            #impl_insert
            #impl_query
            #impl_delete
            #impl_update
        }
    }.into()
}